/**
 * Project: springyounger.lottery.biz.admin
 * 
 * File Created at 2010-4-8
 * $Id$
 * 
 * Copyright 2009 Zjut Croporation Limited.
 * All rights reserved.
 *
 * This software is the confidential and proprietary information of
 * Zjut Edu. ("Confidential Information").  You shall not
 * disclose such Confidential Information and shall use it only in
 * accordance with the terms of the license agreement you entered into
 * with Zjut Edu.
 */
package com.springyounger.lottery.service;

import java.util.List;

import org.apache.log4j.Logger;

import com.springyounger.lottery.dal.dao.PhaseDao;
import com.springyounger.lottery.dal.dataobject.LotteryPrize;
import com.springyounger.lottery.dal.dataobject.LotteryPrizeQuota;

/**
 * 奖品管理
 * 
 * @author springyounger
 */
public class PrizeService {
    private PhaseDao phaseDao;
    private Logger   logger = Logger.getLogger(PrizeService.class);

    /**
     * 获取奖品总数
     * 
     * @return
     */
    public int getAllPrizesCount() {
        try {
            return phaseDao.getAllPrizesCount();
        } catch (Exception e) {
            logger.error("获取奖品总数失败", e);
            return 0;
        }
    }

    /**
     * 获取奖品列表
     * 
     * @param pageIndex
     * @param pageSize
     * @return
     */
    public List<LotteryPrize> getAllPrizes(int pageIndex, int pageSize) {
        try {
            return phaseDao.getAllPrizes(pageIndex, pageSize);
        } catch (Exception e) {
            logger.error("获取奖品列表失败", e);
            return null;
        }
    }

    /**
     * 获取奖品
     * 
     * @param prizeId
     * @return
     */
    public LotteryPrize getPrizeById(int prizeId) {
        try {
            return phaseDao.getPrizeById(prizeId);
        } catch (Exception e) {
            logger.error("获取奖品失败", e);
            return null;
        }
    }

    /**
     * 删除奖品
     * 
     * @param prizeId
     * @return
     */
    public boolean deletePrize(int prizeId) {
        try {
            phaseDao.deletePrize(prizeId);
            return true;
        } catch (Exception e) {
            logger.error("删除奖品失败", e);
            return false;
        }
    }

    /**
     * 创建奖品对象
     * 
     * @param prize
     * @return
     */
    public LotteryPrize insertPrize(LotteryPrize prize) {
        try {
            return phaseDao.insertPrize(prize);
        } catch (Exception e) {
            logger.error("创建奖品对象失败", e);
            return null;
        }
    }

    /**
     * 获取存在奖品
     * 
     * @param prize
     * @return
     */
    public boolean isExistPrize(LotteryPrize prize) {
        try {
            if (phaseDao.isExistPrize(prize) > 0) {
                return true;
            } else {
                return false;
            }
        } catch (Exception e) {
            logger.error("获取存在奖品失败", e);
            return false;
        }
    }

    /**
     * 更新奖品对象
     * 
     * @param prize
     * @return
     */
    public boolean updatePrize(LotteryPrize prize) {
        try {
            phaseDao.updatePrize(prize);
            return true;
        } catch (Exception e) {
            logger.error("更新奖品对象失败", e);
            return false;
        }
    }

    /**
     * 获取符合条件的所有奖品信息
     * 
     * @param phaseId
     * @return
     */
    public List<LotteryPrizeQuota> getAllPrizesByPhaseId(int phaseId) {
        try {
            return phaseDao.getAllPrizesByPhaseId(phaseId);
        } catch (Exception e) {
            logger.error("获取符合条件的所有奖品信息失败", e);
            return null;
        }
    }

    /**
     * 获取符合条件的第一条奖品配额
     * 
     * @param prizeId
     * @return
     */
    public LotteryPrizeQuota getTopPrizeQuota(int prizeId) {
        try {
            return phaseDao.getTopPrizeQuota(prizeId);
        } catch (Exception e) {
            logger.error("获取符合条件的第一条奖品配额失败", e);
            return null;
        }
    }

    /**
     * 批量创建奖品配额
     * 
     * @param quotaList
     * @return
     */
    public boolean batchInsertPrizeQuota(final List<LotteryPrizeQuota> quotaList) {
        try {
            phaseDao.batchInsertPrizeQuota(quotaList);
            return true;
        } catch (Exception e) {
            logger.error("批量创建奖品配额失败", e);
            return false;
        }
    }

    /**
     * 批量更新奖品配额
     * 
     * @param quotaList
     * @return
     */
    public boolean batchUpdatePrizeQuota(final List<LotteryPrizeQuota> quotaList) {
        try {
            phaseDao.batchUpdatePrizeQuota(quotaList);
            return true;
        } catch (Exception e) {
            logger.error("批量更新奖品配额失败", e);
            return false;
        }
    }

    /**
     * @param phaseDao the phaseDao to set
     */
    public void setPhaseDao(PhaseDao phaseDao) {
        this.phaseDao = phaseDao;
    }
}
